package com.example.shopping_web_back.service;

import com.example.shopping_web_back.mapper.ShoppingCarMapper;
import com.example.shopping_web_back.pojo.ShoppingCar;
import com.example.shopping_web_back.service.impl.ShoppingCarServiceImpl;
import com.example.shopping_web_back.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ShoppingCarService implements ShoppingCarServiceImpl {

    @Autowired
    private ShoppingCarMapper shoppingCarMapper;

    @Override
    public List<ShoppingCar> list() {
        Map<String, Object> map = ThreadLocalUtil.get();
        String customerName = (String) map.get("customer_name");
        //3.调用mapper
        List<ShoppingCar> pbShoppingCar = shoppingCarMapper.list(customerName);
        return pbShoppingCar;
    }

    @Override
    public void addGoods(ShoppingCar shoppingCar) {
        shoppingCarMapper.addGoods(shoppingCar);
    }

    @Override
    public void updateGoods(ShoppingCar shoppingCar, Integer num, Boolean is_purchase) {
        shoppingCarMapper.updateGoods(shoppingCar, num, is_purchase);
    }

    @Override
    public void deleteGoods(ShoppingCar shoppingCar) {
        shoppingCarMapper.deleteGoods(shoppingCar);
    }

    @Override
    public ShoppingCar findGoods(ShoppingCar shoppingCar) {
        return shoppingCarMapper.findGoods(shoppingCar);
    }
}
